package cn.wolfcode.controller;

import cn.wolfcode.domain.Classinfo;
import cn.wolfcode.query.ClassinfoQueryObject;
import cn.wolfcode.query.JsonResult;
import cn.wolfcode.service.IClassinfoService;
import cn.wolfcode.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Administrator on 2020/5/6.
 */
@Controller
@RequestMapping("/class")
public class ClassController {
    @Autowired
    private IClassinfoService classinfoService;
    @Autowired
    private IEmployeeService employeeService;
    //查询
    @RequestMapping("/list")
    public String list(Model model,@ModelAttribute("qo")ClassinfoQueryObject qo){
        model.addAttribute("pageInfo",classinfoService.query(qo));
        model.addAttribute("employees",employeeService.listAll());
        return "class/list";
    }
    //保存修改
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(Classinfo classinfo) {
        if (classinfo.getId() != null) {
            classinfoService.update(classinfo);
        } else {
            classinfoService.save(classinfo);
        }
        return new JsonResult();
    }
    //删除
    @RequestMapping("/delete")
    @ResponseBody
    public JsonResult delete(Long id){
        if(id != null){
            classinfoService.delete(id);
        }
        return new JsonResult();
    }





}
